fix(mcp): JSON-serialize order_by_cols and support sort direction#39952
fix(mcp): JSON-serialize order_by_cols and support sort direction#39952scouredimage wants to merge 1 commit intoapache:masterfrom
Conversation
Code Review Agent Run #95b19fActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
The frontend's extractQueryFields.ts expects each entry in order_by_cols to be a JSON-serialized [column, ascending] tuple and calls JSON.parse() on each item. Bare strings caused a parse error and the chart failed to render. This commit: - Adds a SortByConfig schema with explicit `ascending` direction - Extends TableChartConfig.sort_by to accept either a column-name string (defaults to descending — the typical sort-by-metric "top N" pattern) or a SortByConfig object - JSON-serializes each entry as [column, ascending] in map_table_config
40acca7 to
efee1ac
Compare
aminghadersohi
left a comment
There was a problem hiding this comment.
The bug fix is correct — verified against the frontend source at extractQueryFields.ts:115-119, which documents the expected format explicitly in a comment and calls JSON.parse() on each order_by_cols entry. Bare column-name strings cause a SyntaxError there; JSON-serialized [col, bool] tuples are the correct shape.
SortByConfig is a clean addition — validation is tight, the alias (col) and default direction are documented, and the mixed-type union works properly via Pydantic's discriminated parsing.
Tests cover all three paths (bare string, explicit SortByConfig, mixed). Bito confirmed MyPy and Ruff clean.
One minor style note for future PRs: the project's CLAUDE.md prefers lowercase list[str] (Python 3.10+ style) over List[str] from typing — worth adopting on new code even when the surrounding file hasn't been migrated yet.
Code Review Agent Run #ed7b4cActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
SUMMARY
map_table_configin chart_utils.py currently passesconfig.sort_by(a list of bare column-name strings) straight through to the savedform_data["order_by_cols"]. The frontend (packages/superset-ui-core/src/query/extract/extractQueryFields.ts) expects each entry inorder_by_colsto be a JSON-serialized[column, ascending]tuple and callsJSON.parse()on each item — bare strings cause aSyntaxErrorand the chart fails to render.This PR fixes the serialization and additionally exposes sort direction to MCP callers, since the underlying form_data shape supports it but the schema didn't.
Changes
SortByConfigmodel with an explicitascending: bool(defaultFalse).TableChartConfig.sort_bynow acceptsList[str | SortByConfig]. Bare strings default to descending — the natural choice for the sort-by-metric "top N" pattern most common for tables.map_table_configJSON-serializes each entry as[column, ascending].BEFORE/AFTER
TESTING INSTRUCTIONS
The existing
test_map_table_config_with_sortis updated for the new format, and a newtest_map_table_config_with_sort_directioncovers the SortByConfig path and the mixed string/object case.ADDITIONAL INFORMATION